package com.ruoyi.category.service.impl;

import java.util.List;

import com.ruoyi.category.domain.vo.NexusCategoryVo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.category.mapper.NexusCategoryMapper;
import com.ruoyi.category.domain.NexusCategory;
import com.ruoyi.category.service.INexusCategoryService;

/**
 * app类别Service业务层处理
 *
 * @author Afanda
 * @date 2025-04-29
 */
@Service
public class NexusCategoryServiceImpl implements INexusCategoryService {
    final String REDIS_KEY = "category";

    @Autowired
    private NexusCategoryMapper nexusCategoryMapper;

    @Autowired
    private RedisCache redisCache;
    /**
     * 查询app类别
     *
     * @param id app类别主键
     * @return app类别
     */
    @Override
    public NexusCategory selectNexusCategoryById(Long id) {
        return nexusCategoryMapper.selectNexusCategoryById(id);
    }

    /**
     * 查询app类别列表
     *
     * @param nexusCategory app类别
     * @return app类别
     */
    @Override
    public List<NexusCategory> selectNexusCategoryList(NexusCategory nexusCategory) {
        return nexusCategoryMapper.selectNexusCategoryList(nexusCategory);
    }

    /**
     * 新增app类别
     *
     * @param nexusCategory app类别
     * @return 结果
     */
    @Override
    public int insertNexusCategory(NexusCategory nexusCategory) {
        nexusCategory.setCreateTime(DateUtils.getNowDate());
        return nexusCategoryMapper.insertNexusCategory(nexusCategory);
    }

    /**
     * 修改app类别
     *
     * @param nexusCategory app类别
     * @return 结果
     */
    @Override
    public int updateNexusCategory(NexusCategory nexusCategory) {
        nexusCategory.setUpdateTime(DateUtils.getNowDate());
        return nexusCategoryMapper.updateNexusCategory(nexusCategory);
    }

    /**
     * 批量删除app类别
     *
     * @param ids 需要删除的app类别主键
     * @return 结果
     */
    @Override
    public int deleteNexusCategoryByIds(Long[] ids) {
        List<NexusCategory> nexusCategoryList = nexusCategoryMapper.deleteNexusCategoryByIdsGetList(ids);
        System.out.println(nexusCategoryList);
        if(nexusCategoryList != null && nexusCategoryList.size() > 0){
            for(NexusCategory nexusCategory:nexusCategoryList){
                String key = REDIS_KEY + nexusCategory.getCategoryId();
                redisCache.deleteObject(key);
            }
        }
        return nexusCategoryMapper.deleteNexusCategoryByIds(ids);
    }

    /**
     * 删除app类别信息
     *
     * @param id app类别主键
     * @return 结果
     */
    @Override
    public int deleteNexusCategoryById(Long id) {
        return nexusCategoryMapper.deleteNexusCategoryById(id);
    }

    public List<NexusCategoryVo> selectNexusCategoryVoList(NexusCategory nexusCategory) {
        return nexusCategoryMapper.selectNexusCategoryVoList(nexusCategory);
    }

    @Override
    public List<NexusCategory> selectCategoryNameList() {
        return nexusCategoryMapper.selectCategoryNameList();
    }

    @Override
    public List<NexusCategoryVo> selectNexusCategoryListByParentId(Long id) {
        List<NexusCategoryVo> nexusCategoryVos = nexusCategoryMapper.selectNexusCategoryListByParentId(id);
        if (nexusCategoryVos.size() == 0 || nexusCategoryVos == null) {
            return null;
        }
        return nexusCategoryVos;
    }

    @Override
    public List<NexusCategoryVo> selectCategoryNavAll(){

        return nexusCategoryMapper.selectCategoryNavAll();
    }

}
